package com.vitabuybuy.tv.ui.mine.talent.task

import android.os.Bundle
import com.google.android.material.tabs.TabLayout
import com.library.common.util.FragmentUtils
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.FragmentTaskBinding
import com.library.common.base.BaseFragment
import com.vitabuybuy.tv.ui.mine.talent.task.viewmodel.TaskViewModel
import kotlinx.android.synthetic.main.activity_my_bidding.*

class TaskFragment : BaseFragment<TaskViewModel, FragmentTaskBinding>() {
    override val layoutId: Int
        get() = R.layout.fragment_task

    override fun initView(savedInstanceState: Bundle?) {
        showCurrentFragment(0)
        tabLayout.apply {
            addTab(tabLayout.newTab().setText(getString(R.string.task_pool)))
            addTab(tabLayout.newTab().setText(getString(R.string.task_manage)))
        }
    }

    override fun eventHandling() {
        tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener{
            override fun onTabReselected(p0: TabLayout.Tab?) {
            }
            override fun onTabUnselected(p0: TabLayout.Tab?) {
            }
            override fun onTabSelected(tab: TabLayout.Tab?) {
                showCurrentFragment(tab?.position)
            }
        })
    }

    private fun showCurrentFragment(index: Int?) {
        when (index) {
            0 -> FragmentUtils.replaceFragment(
                childFragmentManager,
                R.id.containerFragment,
                TaskPoolFragment::class.java.name
            )
            1 -> FragmentUtils.replaceFragment(
                childFragmentManager,
                R.id.containerFragment,
                TaskManageFragment::class.java.name
            )
        }
    }
}
